require "trifle/ruby/queue/redis_connect"
require "json"

module Trifle
	module Ruby
		class AppException
			attr_reader :app_type, :payload

			def initialize(payload = {})
				@app_type = "exception"
				@payload = payload
			end

			def complete!
				config = Config.load[::Rails.env || ENV["rack_env"] || ENV["RAILS_ENV"]]
				return unless config

				if config["queue"]["enabled"] and config["queue"]["handler"] == "redis"
					redis_connect = Trifle::Ruby::Queue::RedisConnect.new
					redis_connect.push(self.to_json)
				else
					Trifle::Ruby::Handler.submit!("exceptions", [self].to_json)
				end
			end
		end
	end
end
